<link rel="stylesheet" href="__PUBLIC__/Home/style/order.css" type="text/css">
<link rel="stylesheet" href="__PUBLIC__/Home/style/address.css" type="text/css">
<script type="text/javascript" src="__PUBLIC__/Home/js/home.js"></script>
<link rel="stylesheet" href="__PUBLIC__/Home/style/home.css" type="text/css">
<include file="Common/nav"/>
<!-- 页面主体 start -->
<div class="main w1210 bc mt10">
    <div class="crumb w1210">
        <h2><strong>我的XX </strong><span> 我的订单</span></h2>
    </div>
    <include file="My/menu"/>
    <!-- 右侧内容区域 start -->
    <div class="content fl ml10">
        <div class="address_hd">
            <h3>收货地址薄</h3>
            <?php foreach($data as $k => $v):?>
            <dl>
                <dt id="">
                    {$v.consignee}
                    <?php echo $v['province']['region_name'];?>
                    <?php echo $v['city']['region_name'];?>
                    <?php echo $v['district']['region_name'];?>
                    {$v.address}
                    {$v.mobile}
                    <?php if($v['is_default']==1):?><font color="red">[默认]</font><?php endif?>
                </dt>
                <dd>
                    <a href="{:U('UserAddress/edit')}?id={$v.id}">修改</a>
                    <a <?php if($v['is_default']==1) echo hidden?> href="{:U('UserAddress/delete')}?id={$v.id}" onclick="if(!confirm('是否删除该地址?')){return false}">删除</a>
                    <a href="{:U('UserAddress/setDefault')}?id={$v.id}" onclick="if(!confirm('是否设置为默认地址!')){return false}">设为默认地址</a>
                </dd>
            </dl>
            <?php endforeach ?>
        </div>

        <div class="address_bd mt10">
            <h4>新增/修改收货地址</h4>
            <form action="<?php if($info):echo U('UserAddress/edit');else:echo U('UserAddress/add');?><?php endif?>" name="address_form" method="post">
                <ul>
                    <li>
                        <label for=""><span>*</span>收 货 人：</label>
                        <input type="text" name="consignee" class="txt" value="{$info.consignee}"/>
                    </li>
                    <li>
                        <label for=""><span>*</span>所在地区：</label>
                        <select name="province" id="province">
                            <option value="">请选择</option>
                        </select>

                        <select name="city" id="city">
                            <option value="">请选择</option>
                        </select>

                        <select name="district" id="district">
                            <option value="">请选择</option>
                        </select>
                    </li>
                    <li>
                        <label for="address"><span>*</span>详细地址：</label>
                        <input type="text" name="address" id="address" class="txt address" value="{$info.address}" />
                    </li>
                    <li>
                        <label for="mobile"><span>*</span>手机号码：</label>
                        <input type="text" name="mobile" id="mobile" class="txt" value="{$info.mobile}"/>
                    </li>
                    <li>
                        <label for="">&nbsp;</label>
                        <input type="submit" class="btn" value="保存" />
                        <a href="{:U('UserAddress/lst')}">添加</a>
                    </li>
                </ul>
                <input type="hidden" name="member_id" value="{$info.member_id}" />
                <input type="hidden" name="id" value="{$info.id}" />
            </form>
        </div>

    </div>
    <!-- 右侧内容区域 end -->
</div>
<!-- 页面主体 end-->

<!-- 底部导航 end -->
<!-- 页面主体 start -->
<script>

    $(function () {
        <?php if($info):?>
        var region ={province:"{$info.province}",city:"{$info.city}",district:"{$info.district}"};
        $.each(region,function (region_name,region_id) {
            if(region_name == 'province'){
                parent_region_id =1;
            }else if(region_name=='city'){
                parent_region_id =region.province;
            }else if(region_name=='district'){
                parent_region_id = region.city;
            }
            $.ajax({
                url:'<?php echo U("UserAddress/region")?>',
                type:'get',
                data:'id='+parent_region_id,
                dataType:'json',
                success:function (data) {
                    $.each(data,function (k,v) {
                        $('#'+region_name).append(new Option(v.region_name,v.region_id,(region_id==v.region_id ? true : false),
                            (region_id==v.region_id ? true:false)));

                    });
                }
            });
    });
        <?php else:?>
        $.ajax({
            url:'<?php echo U("UserAddress/region")?>',
            type:'get',
            dataType:'json',
            success:function (data) {
                $.each(data,function (k,v) {
                    $('#province').append("<option value='"+v.region_id+"'>"+v.region_name+"</option>");
                });
            }
        });
<?php endif;?>
        $("#province,#city").change(function () {
            var select = $(this);
            $.ajax({
                url:'<?php echo U("UserAddress/region")?>',
                type:'get',
                data:'id='+select.val(),
                dataType:'json',
                success:function (data) {
                    select.nextAll('select').empty().append(new Option('请选择'));
                    $.each(data,function (k,v) {
                        select.next().append(new Option(v.region_name,v.region_id));
                    });
                }
            });
        });
    });

</script>
<include file="Common/help"/>